package com.zonski.jbots.desktop.editer;

import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: Oct 27, 2003
 * Time: 9:51:22 AM
 * To change this template use Options | File Templates.
 */
public abstract class AbstractMouseTool extends AbstractTool
{
    private MouseListener mouseListener;
    private MouseMotionListener mouseMotionListener;

    public AbstractMouseTool()
    {
        this.mouseListener = createMouseListener();
        this.mouseMotionListener = createMouseMotionListener();
    }

    /**
     * creates a mouse listener for the tool
     * @return the new mouse listener
     */
    protected MouseListener createMouseListener()
    {
        return null;
    }

    protected MouseMotionListener createMouseMotionListener()
    {
        return null;
    }

    protected void doActivate()
    {
        super.doActivate();
        if(this.mouseListener != null)
        {
            this.getContext().getComponent().addMouseListener(this.mouseListener);
        }
        if(this.mouseMotionListener != null)
        {
            this.getContext().getComponent().addMouseMotionListener(this.mouseMotionListener);
        }
    }

    protected void doDeactivate()
    {
        super.doDeactivate();
        if(this.mouseListener != null)
        {
            this.getContext().getComponent().removeMouseListener(this.mouseListener);
        }
        if(this.mouseMotionListener != null)
        {
            this.getContext().getComponent().removeMouseMotionListener(this.mouseMotionListener);
        }
    }
}
